RECHARGE_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'target_event_id': ['recharge', 'recharge_apply'],
    'interval_type_list': ['day', 'week', 'month'],
    'values': [
        {
            "value_id": "recharge_count",
            "target_value": "_user_id",
            "value_name": "充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "recharge_price",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "recharge_total_count",
            "target_value": "_user_id",
            "value_name": "总充值订单",
            "filter": [
                {"term": {"_event_id": "recharge_apply"}},
            ],
            "operation": "value_count",
            "value_type": "long",
            "hide_result": True,
        },
        {
            "value_id": "recharge_success_rate",
            "value_name": "充值成功率",
            "value_expr": "recharge_count / recharge_total_count",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "justpay_recharge_count",
            "target_value": "_user_id",
            "value_name": "justpay充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['alipay', 'quota_alipay', 'justpay']}}
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "justpay_recharge_price",
            "target_value": "recharge_price",
            "value_name": "justpay充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['alipay', 'quota_alipay', 'justpay']}}
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "justpay_recharge_total_count",
            "target_value": "_user_id",
            "value_name": "justpay充值订单",
            "filter": [
                {"term": {"_event_id": "recharge_apply"}},
                {'terms': {'recharge_apply_sub_type.keyword': ['alipay', 'quota_alipay', 'justpay']}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "hide_result": True,
        },
        {
            "value_id": "justpay_recharge_success_rate",
            "value_name": "justpay充值成功率",
            "value_expr": "justpay_recharge_count / justpay_recharge_total_count",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "unionagency_recharge_count",
            "target_value": "_user_id",
            "value_name": "unionagency充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'recharge_sub_type.keyword': 'unionagency'}}
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "unionagency_recharge_price",
            "target_value": "recharge_price",
            "value_name": "unionagency充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'recharge_sub_type.keyword': 'unionagency'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "unionagency_recharge_total_count",
            "target_value": "_user_id",
            "value_name": "unionagency充值订单",
            "filter": [
                {"term": {"_event_id": "recharge_apply"}},
                {"term": {"recharge_apply_sub_type.keyword": 'unionagency'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "hide_result": True,
        },
        {
            "value_id": "unionagency_recharge_success_rate",
            "value_name": "unionagency充值成功率",
            "value_expr": "unionagency_recharge_count / unionagency_recharge_total_count",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "agency_pay_recharge_count",
            "target_value": "_user_id",
            "value_name": "代理充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "agency_pay_recharge_price",
            "target_value": "recharge_price",
            "value_name": "代理充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "agency_pay_recharge_total_count",
            "target_value": "_user_id",
            "value_name": "代理充值充值订单",
            "filter": [
                {"term": {"_event_id": "recharge_apply"}},
                {'terms': {'recharge_apply_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "value_count",
            "value_type": "long",
            "hide_result": True,
        },
        {
            "value_id": "agency_pay_recharge_success_rate",
            "value_name": "代理充值成功率",
            "value_expr": "agency_pay_recharge_count / agency_pay_recharge_total_count",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },

    ]
}


AVERAGE_RECHARGE_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'target_event_id': ['recharge', 'recharge_apply'],
    'interval_type_list': ['day', 'week', 'month'],
    'values': [
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "recharge_count",
            "target_value": "_user_id",
            "value_name": "充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "operation": "value_count",
            "hide_result": True
        },
        {
            "value_id": "recharge_price",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "value_type": "float",
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "average_recharge_count",
            "value_name": "人均充值次数",
            "value_expr": "recharge_count / recharge_user",
        },
        {
            "value_id": "average_recharge",
            "value_name": "人均充值",
            "value_expr": "recharge_price / recharge_user",
            "adjust_amount": True,
        },
        {
            "value_id": "justpay_recharge_user",
            "target_value": "_user_id",
            "value_name": "在线充值账号",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {'terms': {'recharge_sub_type.keyword': ['alipay', 'quota_alipay', 'justpay']}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "justpay_recharge_count",
            "target_value": "_user_id",
            "value_name": "在线充值次数",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {'terms': {'recharge_sub_type.keyword': ['alipay', 'quota_alipay', 'justpay']}}
            ],
            "operation": "value_count",
            "hide_result": True
        },
        {
            "value_id": "justpay_recharge_price",
            "target_value": "recharge_price",
            "value_name": "在线充值金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {'terms': {'recharge_sub_type.keyword': ['alipay', 'quota_alipay', 'justpay']}}
            ],
            "value_type": "float",
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "justpay_average_recharge_count",
            "value_name": "在线充值人均次数",
            "value_expr": "justpay_recharge_count / justpay_recharge_user",
        },
        {
            "value_id": "justpay_average_recharge",
            "value_name": "在线充值人均金额",
            "value_expr": "justpay_recharge_price / justpay_recharge_user",
            "adjust_amount": True,
        },

        {
            "value_id": "unionagency_recharge_user",
            "target_value": "_user_id",
            "value_name": "银行卡充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'recharge_sub_type.keyword': 'unionagency'}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "unionagency_recharge_count",
            "target_value": "_user_id",
            "value_name": "银行卡充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'recharge_sub_type.keyword': 'unionagency'}}
            ],
            "operation": "value_count",
            "hide_result": True
        },
        {
            "value_id": "unionagency_recharge_price",
            "target_value": "recharge_price",
            "value_name": "银行卡充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'recharge_sub_type.keyword': 'unionagency'}}
            ],
            "value_type": "float",
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "unionagency_average_recharge_count",
            "value_name": "银行卡充值人均次数",
            "value_expr": "unionagency_recharge_count / unionagency_recharge_user",
        },
        {
            "value_id": "unionagency_average_recharge",
            "value_name": "银行卡充值人均金额",
            "value_expr": "unionagency_recharge_price / unionagency_recharge_user",
            "adjust_amount": True,
        },
        {
            "value_id": "agency_recharge_user",
            "target_value": "_user_id",
            "value_name": "代理充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality"
        },
        {
            "value_id": "agency_recharge_count",
            "target_value": "_user_id",
            "value_name": "代理充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "value_count",
            "hide_result": True
        },
        {
            "value_id": "agency_recharge_price",
            "target_value": "recharge_price",
            "value_name": "代理充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "agency_average_recharge_count",
            "value_name": "代理充值人均次数",
            "value_expr": "agency_recharge_count / agency_recharge_user",
        },
        {
            "value_id": "agency_average_recharge",
            "value_name": "代理充值人均金额",
            "value_expr": "agency_recharge_price / agency_recharge_user",
            "adjust_amount": True,
        }
    ]
}
